import React from 'react';
import {connect} from 'dva/index';
import {Select} from 'antd';

const R = require('ramda');

const Option = Select.Option;


class RoleSelect extends React.Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {
        this.props.dispatch({
            type: 'app/getUsersByRole',
            payload: {
                role: this.props.role
            }
        });
    }

    render() {
        let list = this.props.app[this.props.role] ? this.props.app[this.props.role] : [];
        return (
            <Select showSearch {...R.omit(['app'])(this.props) } style={this.props.style} allowClear>
                {
                    list.map(item => {
                        return (<Option value={item.userId + ""} key={item.userId + ""}>{item.username}</Option>);
                    })
                }
            </Select>
        );
    }
}

export default connect(({ app }) => ({ app }))(RoleSelect)

RoleSelect.propTypes = {
    role: React.PropTypes.string.isRequired
}